class QueryEntity {
    constructor({
                    fileName = '',
                    fileId = '',
                    fileComments = '',
                    fileNameAction = '1',
                    fileIdAction = '1',
                    fileCommentsAction = '1',
                    timeArray = '',
                    communicateType = '',
                    fileType = '',
                    startTime = '',
                    endTime = '',
                } = {}) {
        this.fileName = fileName;
        this.fileId = fileId;
        this.fileComments = fileComments;
        this.fileNameAction = fileNameAction;
        this.fileIdAction = fileIdAction;
        this.fileCommentsAction = fileCommentsAction;
        this.timeArray = timeArray;
        this.communicateType = communicateType;
        this.fileType = fileType;
        this.startTime = startTime;
        this.endTime = endTime;

    }
}

const app = new BasicTableVue({
    data: function () {
        return {
            api: netCommunicationLogApi,
            columns: [
                TableColumn.generate({
                    type: 'selection',
                    width: 30,
                    align: 'center',
                }),
                TableColumn.generate({sortable: false, prop: 'id', title: '编号', align: 'center'}),
                TableColumn.generate({sortable: false, prop: 'fileName', title: '备案文件名称', align: 'center'}),
                TableColumn.generate({
                    sortable: false,
                    prop: 'communicateType',
                    title: '通讯类型',
                    align: 'center',
                    formatter: this.communicateTypeFormat,
                }),
                TableColumn.generate({
                    sortable: false,
                    prop: 'fileType',
                    title: '文件类型',
                    align: 'center',
                    formatter: this.fileTypeFormat,
                }),
                TableColumn.generate({
                    sortable: false,
                    prop: 'createTime',
                    title: '创建时间',
                    align: 'center',
                    formatter: TableColumn.datetimeFormat,
                }),
                TableColumn.generate({sortable: false, prop: 'fileComments', title: '文件备注', align: 'center'}),
                TableColumn.generate({
                    prop: 'operating',
                    title: '操作',
                    customComponent: 'true',
                    sortable: false,
                    align: 'center',
                }),
            ],
            communicateTypeMap: new Map()
                .set(1, '下载')
                .set(2, '上报')
                .set(3, '导入')
                .set(4, '下发EU')
                .set(5, 'EU上报')
                .set(6, '下发DU')
                .set(7, 'DU上报'),
            fileTypeMap: new Map()
                .set(1, '基础数据')
                .set(2, '监测数据')
                .set(3, '日志查询')
                .set(4, '监测日志')
                .set(5, '过滤日志')
                .set(6, '指令查询')
                .set(7, '活动状态')
                .set(8, '活跃资源')
                .set(9, '违规监测')
                .set(10, '非法监控')
                .set(11, 'EU同步'),

        }
    },
    methods: {
        createForm() {
            return new QueryEntity();
        },
        async deleteOne(row) {
            const cfVal = await rxPrompt.confirm('是否确认删除', ['确认', '取消'])
            if (!cfVal) {
                return;
            }
            const res = await netCommunicationLogApi.delete(row.id);
            if (res) {
                if (res.code == 200) {
                    await rxPrompt.msg('移除成功')
                    await this.searchPage()
                    return;
                }
            }
            await rxPrompt.msg(`移除失败,${res.msg}`)

        },
        communicateTypeFormat(row, column, val, key) {
            return this.communicateTypeMap.get(parseInt(val));
        },
        fileTypeFormat(row, column, val, key) {
            return this.fileTypeMap.get(parseInt(val));
        },
        async batchDownload() {
            const ids = this.selectedIdList;
            if (ids.length == 0) {
                await rxPrompt.msg('请勾选要下载的文件')
                return;
            }

            await axiosDownloadUtils.postDownloadUrl('/api/netCommunicationLog/download-files', '通讯资源.zip', ids)

        },
        // 下载文件
        download(data) {
            if (!data) {
                return
            }
            let url = window.URL.createObjectURL(new Blob([data]))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', 'a.zip')

            document.body.appendChild(link)
            link.click()
        },
    },
    watch: {
        'form.timeArray': function (newVal, oldVal) {
            if (newVal) {
                this.form.startTime = newVal[0];
                this.form.endTime = newVal[1];
            } else {
                this.form.startTime = '';
                this.form.endTime = '';
            }

        },
    },
})